package src;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;

public class GameFrame extends JFrame{
	
	private static final long serialVersionUID = 1L;
	private boolean running = false;
	private int width = 800, height = 640, fps = 60;
	private BufferedImage bb  = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
	InputHandler input;
	Player player;
	World world;
	
	public static void main(String[] args) {
		GameFrame game = new GameFrame();
		game.run();
		System.exit(0);
	}
	
	public void run(){
		initialise();
		while(running){
			long time = System.currentTimeMillis();
			update();
			draw();
			time = (1000 / fps) - (System.currentTimeMillis() - time);
			if(time > 0){
				try{
					Thread.sleep(time);
				}
				catch(Exception ex){	
					System.out.println(ex.getMessage());
				}
			}
		}
	}
	
	public void initialise(){
		running = true;
		setVisible(true);
		setSize(width, height);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		input = new InputHandler(this);
		world = new World();
	}
	
	public void update(){
		
	}
	
	public void draw(){
		Graphics g = getGraphics();
		Graphics bbg = bb.getGraphics();
		world.draw(bbg);
		g.drawImage(bb, 0, 0, this);
	}
}
